package javaweblearn.session;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//避免表单重复提交
public class FormServlet extends HttpServlet {

    private static final long serialVersionUID = -884689940866074733L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String token = TokenProccessor.getInstance().makeToken();
        req.getSession().setAttribute("token", token);  //在服务器使用session保存token(令牌)
        System.out.println("在FormServlet中生成的token："+token);
        req.getRequestDispatcher("/form.jsp").forward(req, resp);//跳转到form.jsp页面
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
